var ds = new Ext.data.Store({
			proxy : new Ext.data.HttpProxy({
						url : 'manuscript_one_list.action',
						method : 'POST'
					}),
			reader : new Ext.data.JsonReader({
						root : 'manuscripts',
						totalProperty : 'totalCount'
					}, [{
								name : 'manuscriptId',
								mapping : 'manuscriptId',
								type : 'long',
								hidden : 'true'
							}, {
								name : 'title',
								mapping : 'title',
								type : 'string'
							}, {
								name : 'type',
								mapping : 'type',
								type : 'short'
							}, {
								name : 'language',
								mapping : 'language',
								type : 'short'
							}, {
								name : 'targetLanguage',
								mapping : 'targetLanguage',
								type : 'short'
							}, {
								name : 'status',
								mapping : 'status',
								type : 'short'
							}, {
								name : 'securityClassification',
								mapping : 'securityClassification',
								type : 'short'
							}, {
								name : 'urgence',
								mapping : 'urgence',
								type : 'short'
							}, {
								name : 'operation',
								type : 'string'
							}])
		});
		
function tourgence(value) {
	switch (value) {
		case 0 :
			return "普通";
			break;
		case 5 :
			return "紧急";
			break;
		case 10 :
			return "特急";
			break;
	}
}

function tosecurityClassification(value) {
	switch (value) {
		case 1 :
			return "普通";
			break;
		case 2 :
			return "秘密";
			break;
		case 3 :
			return "机密";
			break;
		case 5 :
			return "绝密";
			break;
	}
}
//稿件标识图标与光标提示 begin
var re;
function markchange(value, metadata, record) {
    var title = '&nbsp;密级&nbsp;&nbsp;&nbsp;&nbsp;紧急程度&nbsp;';
    var tip;
    var s1 = "&nbsp;普通&nbsp;&nbsp;&nbsp;&nbsp;";
    var s2 = "&nbsp;秘密&nbsp;&nbsp;&nbsp;&nbsp;";
    var s3 = "&nbsp;机密&nbsp;&nbsp;&nbsp;&nbsp;";
    var s5 = "&nbsp;绝密&nbsp;&nbsp;&nbsp;&nbsp;";
    var u0 = "&nbsp;&nbsp;&nbsp;普通&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
    var u5 = "&nbsp;&nbsp;&nbsp;紧急&nbsp;&nbsp;&nbsp;&nbsp;";
    var u10 = "&nbsp;&nbsp;&nbsp;特急";
    var c0 = "&nbsp<img src='images/clock_blue.gif'  />&nbsp";// 普通urgence
    var c5 = "&nbsp<img src='images/clock_green.gif' />&nbsp";// 紧急
    var c10 = "&nbsp<img src='images/clock_red.gif' />&nbsp";// 特急
    var l1 = "&nbsp<img src='images/lock_blue.gif'  />&nbsp";// 普通securityClassification
    var l2 = "&nbsp<img src='images/lock_gold.gif'/>&nbsp"; // 秘密
    var l3 = "&nbsp<img src='images/lock_green.gif' />&nbsp";// 机密
    var l5 = "&nbsp<img src='images/lock_red.gif'  />&nbsp";// 绝密
    switch (record.data.securityClassification) {
        case 1:
            switch (record.data.urgence) {
                case 0:
                	re = l1 + c0;
                    tip = s1 + u0;
                    break;
                case 5:
                	re = l1 + c5 ;
                    tip = s1 + u5;
                    break;
                case 10:
                	re = l1 + c10;
                    tip = s1 + u10;
                    break;
            }
            break;
        case 2:
            switch (record.data.urgence) {
                case 0:
                	re = l2 + c0;
                    tip = s2 + u0;
                    break;
                case 5:
                	re = l2 + c5;
                    tip = s2 + u5;
                    break;
                case 10:
                	re = l2 + c10;
                    tip = s2 + u10;
                    break;
            }
            break;
        case 3:
            switch (record.data.urgence) {
	            case 0:
	            	re = l3 + c0;
	                tip = s3 + u0;
	                break;
	            case 5:
	            	re = l3 + c5;
	                tip = s3 + u5;
	                break;
	            case 10:
	            	re = l3 + c10;
	                tip = s3 + u10;
	                break;
            }
            
            break;
        case 5:
            switch (record.data.urgence) {
	            case 0:
	            	re = l5 + c0;
	                tip = s5 + u0;
	                break;
	            case 5:
	            	re = l5 + c5;
	                tip = s5 + u5;
	                break;
	            case 10:
	            	re = l5 + c10;
	                tip = s5 + u10;
	                break;
	            }
            break;
    }
    metadata.attr = 'ext:qtitle="' + title + '"' + ' ext:qtip="' + tip + '"';
    return re;
}
//稿件标识图标与光标提示 end

var cm_menuscript = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(), {
	header : "稿件标题",
	width : 120,
	dataIndex : 'title',
	sortable : true,
	renderer : function(value, metadata, record) {
		return "<a href = 'javascript:void(0)' onclick=javascript:showManuscript('"
				+ record.data.manuscriptId + "')> " + escapeHTML(value) + " </a>";
	}
}, {
	header : "稿件类型",
	width : 120,
	dataIndex : 'type',
	sortable : true,
	renderer : function(value, metadata, record) {
		if (value == 0) {
			return '纸质稿件';
		} else {
			return '电子稿件';
		};
	}
}, {
	header : "原稿文种",
	width : 120,
	dataIndex : 'language',
	sortable : true,
	renderer : function(value, metadata, record) {
		if (value == 1) {
			return '汉语';
		} else if (value == 2) {
			return '藏语';
		};
	}
}, {
	header : "目标语言",
	width : 120,
	dataIndex : 'targetLanguage',
	sortable : true,
	renderer : function(value, metadata, record) {
		if (value == 1) {
			return '汉语';
		} else if (value == 2) {
			return '藏语';
		};
	}
}, {
	header : "稿件状态",
	width : 120,
	dataIndex : 'status',
	sortable : true,
	renderer : function(value, metadata, record) {
		if (value == 0) {
			return '草稿';
		} else if (value == 1) {
			return '原稿';
		} else if (value == 2) {
			return '翻译中';
		} else if (value == 3) {
			return '翻译完成';
		} else if (value == 4) {
			return '校审中';
		} else if (value == 5) {
			return '校审完成';
		} else if (value == 6) {
			return '校对中';
		} else if (value == 7) {
			return '校对完成';
		} else if (value == 8) {
			return '审核中';
		} else if (value == 9) {
			return '审核完成';
		} else {
			return '已发排';
		};
	}
}, {header:'标识',sortable:true,renderer:function drawmark(value, metadata, record)
		{
			return markchange(value, metadata, record);
		}
}, {
	header : "操作",
	width : 120,
	dataIndex : 'operation',
	sortable : true,
	renderer : function(value, metadata, record) {
		if (record.data.status == 10) {
			return "<font color='#cccccc'>修改</font> &nbsp;&nbsp;<a href='javascript:void(0)' onclick=javascript:deleteScript('"
					+ record.data.manuscriptId + "')>删除</a>";
		} else {
			return "<a href = 'javascript:void(0)' onclick=javascript:modifyScript('"
					+ record.data.manuscriptId
					+ "')>修改 </a> &nbsp;&nbsp;<font color='#cccccc'>删除</font>";
		}

	}
}]);

var storeContributeCompany = new Ext.data.JsonStore({
	url : 'contributeCompany_active_list.action',
	root : 'contributeCompanys',
	fields : ['contributeCompanyId', 'contributeCompanyName']
});
storeContributeCompany.load();

var select_manuscript = new Ext.Button({

	text : '查找稿件',
	width : 100,
	iconCls:'manuscript_search',
	handler : function() {
		manuscriptForm = new Ext.form.FormPanel({
			labelAlign : 'right',
			id : 'aa',
			labelWidth : 80,
			frame : true,
			width : 600,
			store : ds,
			items : [{
				xtype : 'combo',
				store : new Ext.data.SimpleStore({
							data : [ ['1', '原稿'], ['2', '翻译中'],
									['3', '翻译完成'], ['4', '校审中'], ['5', '校审完成'],
									['6', '校对中'], ['7', '校对完成'], ['8', '审核中'],
									['9', '审核完成'], ['10', '已发排']],
							fields : ['value', 'text']
						}),
				fieldLabel : '稿件状态',
				hiddenName : 'manuscriptStatus',
				editable : false,
				emptyText : '请选择',
				mode : 'local',
				triggerAction : 'all',
				valueField : 'value',
				displayField : 'text',
				itemCls : 'form_text'
			}, {
				xtype : 'combo',
				store : storeContributeCompany,
				fieldLabel : '来稿单位',
				hiddenName : 'contributeCompanyId',
				editable : false,
				emptyText : '请选择',
				mode : 'local',
				triggerAction : 'all',
				valueField : 'contributeCompanyId',
				displayField : 'contributeCompanyName',
				itemCls : 'form_text'
			},{
				xtype : 'combo',
				store : new Ext.data.SimpleStore({
							data : [['0', '纸质稿件'], ['256', '电子稿件']],
							fields : ['value', 'text']
						}),
				fieldLabel : '稿件类型',
				hiddenName : 'manuscriptType',
				editable : false,
				emptyText : '请选择',
				mode : 'local',
				triggerAction : 'all',
				valueField : 'value',
				displayField : 'text',
				itemCls : 'form_text'
			}, {
				xtype : 'datefield',
				name : 'startTime',
				id : 'startTime',
				editable : false,
				fieldLabel : '开始日期',
				format : 'Y-m-d',
				itemCls : 'form_text',
				minValue:'2008-01-01',
				maxValue : '2020-12-31'
			}, {
				xtype : 'datefield',
				name : 'endTime',
				id : 'endTime',
				editable : false,
				fieldLabel : '结束日期',
				format : 'Y-m-d',
				itemCls : 'form_text',
				minValue:'2008-01-01',
				maxValue : '2020-12-31'
			}],
			buttons : [{
						text : '查找',
						type : 'submit',
						handler : function() {
				
							var startTime = Ext.getCmp('startTime').getValue();
							var endTime = Ext.getCmp('endTime').getValue();
							
							if( startTime != '' && endTime != '')
							{
								if(startTime > endTime)
								{
									Ext.Msg.show({
										title : '错误提示',
											msg : '开始时间必须小于结束时间',
											buttons : Ext.Msg.OK,
											icon : Ext.Msg.INFO,
											width : 200
										});
									return;
								}
							}
							
							
							ds.baseParams = manuscriptForm.getForm()
									.getValues();
							ds.load({
										params : {
											start : 0,
											limit : 20
										}
									});
							window_select_manuscript.remove(Ext.getCmp('aa'));
							window_select_manuscript.close();
						}
					},{
						text:'关闭',
						handler:function(){
						window_select_manuscript.close();
					}
					}]
		});

		var window_select_manuscript = new Ext.Window({
					title : '查找稿件',
					width : 600,
					iconCls:'manuscript_search',
					resizable : false,
					autoHeight : true,
					constrain :true,
					modal : true,
					closable : false,
					closeAction : 'hide',
					items : manuscriptForm
				}).show();
	}
});

//周振山增加修改*************************************

var security = '';
function realSecurity(){
    switch (userSecurityGrade) {
        case '1':
            return security = [['1', '普通']];
            break;
        case '2':
            return security = [['1', '普通'], ['2', '秘密']];
            break;
        case '3':
            return security = [['1', '普通'], ['2', '秘密'], ['3', '机密']];
            break;
        case '5':
            return security = [['1', '普通'], ['2', '秘密'], ['3', '机密'], ['5', '绝密']];
            break;
    }
}

realSecurity();

var storeSecurity= new Ext.data.SimpleStore({
    fields: ['value', 'text'],
    data: security
});

var type = [
	['0','纸质稿件'],
	['256','电子稿件']
];

var storeType = new Ext.data.SimpleStore({
    fields: ['value', 'text'],
    data: type
});

var urgence = [
	['0','普通'],
	['5','紧急'],  
	['10','特急']
];

var storeUrgence= new Ext.data.SimpleStore({
	fields: ['value', 'text'],
	data: urgence
});

var language = [
	['1','汉语'],
	['2','藏语']
];

var storeLanguage= new Ext.data.SimpleStore({
	fields: ['value', 'text'],
	data: language
});

var storeCategory=new Ext.data.JsonStore({
	url : 'manuscriptCategory_list.action',
	root : 'manuscriptCategorys',
	fields : ['manuscriptCategoryId', 'manuscriptCategoryName']
});

storeCategory.load();

var ccontributeCompanyId=0;
var storeContributeCompanyPerson = new Ext.data.JsonStore({
	url : 'contributeCompanyPerson_active_list.action',
	baseParams:{contributeCompanyId:ccontributeCompanyId},
	root : 'contributeCompanyPersons',
	fields : ['contributeCompanyPersonId', 'name']
});
var file ="";


var add_manuscript = new Ext.Button({
	text : '新增稿件',
	hidden:true,
	width : 100,
	iconCls:'manuscript_add',
	handler : function() {
	var form_receiver = new Ext.form.FormPanel({
    iconCls: 'receiver_add',
    id: 'mmd',
    labelAlign: 'right',
    labelWidth: 94,
    frame: true,
    autoScroll: true,
    fileUpload: true,
    region: 'center',
    items: [{
        xtype: 'combo',
        store: storeType,
        hiddenName: 'manuscript.type',
        allowBlank: false,
        editable: false,
        fieldLabel: '稿件类型',
        emptyText: '请选择',
        mode: 'local',
        id: 'typeCombo',
        triggerAction: 'all',
        valueField: 'value',
        displayField: 'text',
        itemCls: 'form_text clear',
        listeners: {
            "select": function(){
                if (Ext.getCmp('typeCombo').getValue() == 0) {
                    form_receiver.remove(Ext.getCmp('uploadField'));
                }
                else {
                    form_receiver.remove(Ext.getCmp('uploadField'));
                    file = new Ext.form.FileUploadField({
                        fieldLabel: '稿件上传',
                        name: 'fileuploadfield',
                        id: 'uploadField',
                        emptyText: '请选择文件(最大允许值50M)',
                        allowBlank: false,
                        width: '410',
                        validator:function(value){
	                  	  var type=['rar','doc','xls','pdf','ppt','txt','zip','docx'];
	                  		if(value==''){
	                  			return '请上传稿件';
	                  		}else{
	                  			var fileType=value.substring(value.lastIndexOf(".")+1).toLowerCase();
	                  			for(var i=0;i<type.length;i++){
	                  				if(type[i]==fileType){
	                  					return true;
	                  				}
	                  			}
	                  			return '请上传如下格式的文件:[rar,doc,xls,pdf,ppt,txt,zip,docx]';
	                  		}
                    	},
                        itemCls: 'clear'
                    });
                    form_receiver.add(file);
                    form_receiver.doLayout();
                }
            }
        }
    }, {
        layout: 'fit',
        items: [{
            title: '详细信息',
            autoHeight: true,
            xtype: 'fieldset',
            layout: 'form',
            xtype: 'fieldset',
            items: [{
                xtype: 'textfield',
                name: 'manuscript.title',
                allowBlank: false,
                fieldLabel: '稿件标题',
                width: 420,
                maxLength: 50
            }, {
                xtype: 'combo',
                id: 'contributeCompanyIdCombo',
                store: storeContributeCompany,
                hiddenName: 'contributeCompanyId',
                allowBlank: false,
                editable: false,
                fieldLabel: '来稿单位',
                emptyText: '请选择',
                mode: 'local',
                triggerAction: 'all',
                valueField: 'contributeCompanyId',
                itemCls: 'form_text',
                displayField: 'contributeCompanyName',
                listeners: {
                    "select": function(){
                    	var contributeCompanyId=Ext.getCmp('contributeCompanyIdCombo').getValue();
			    		Ext.Ajax.request({
			    			url : 'manuscriptCategoryByContributeCompany_get.action',
			    			method : 'post',
			    			params : {
			    				contributeCompanyId : contributeCompanyId
			    			},
			    			success : function(resp, opts) {
								var respText = Ext.util.JSON.decode(resp.responseText);
								Ext.getCmp('manuscriptCategoryName').setValue(respText.manuscriptCategoryName);
								Ext.getCmp('manuscriptCategoryName').hiddenField.value = respText.manuscriptCategoryId;
			    			}
			    			});
                        storeContributeCompanyPerson.baseParams.contributeCompanyId = contributeCompanyId;
                        storeContributeCompanyPerson.load();
                        Ext.getCmp('contributeCompanyPerson').setValue('');
                    }/*,
                    "focus": function(){
                        if (storeContributeCompany.getTotalCount() == 0) {
                            Ext.Msg.show({
                                title: '操作提示',
                                msg: '请管理员添加来稿单位!',
                                buttons: Ext.Msg.OK,
                                icon: Ext.Msg.INFO,
                                width: 200
                            });
                        }
                    }*/
                }
            }, {
                xtype: 'combo',
                store: storeContributeCompanyPerson,
                hiddenName: 'manuscript.contributeCompanyPersonId',
                allowBlank: false,
                editable: false,
                fieldLabel: '联系人',
                emptyText: '请选择',
                mode: 'local',
                id: 'contributeCompanyPerson',
                triggerAction: 'all',
                valueField: 'contributeCompanyPersonId',
                displayField: 'name',
                itemCls: 'form_text',
                listeners: {
                    "focus": function(){
                        if (storeContributeCompanyPerson.getTotalCount() == 0) {
                            Ext.Msg.show({
                                title: '操作提示',
                                msg: '该单位暂无人员，请联系管理员!',
                                buttons: Ext.Msg.OK,
                                icon: Ext.Msg.INFO,
                                width: 200
                            });
                        }
                    }
                }
            }, {
                xtype: 'combo',
                store: storeCategory,
                hiddenName: 'manuscript.manuscriptCategoryId',
                allowBlank: false,
                editable: false,
                fieldLabel: '稿件分类',
                emptyText: '请选择',
                mode: 'local',
                triggerAction: 'all',
                itemCls: 'form_text',
                valueField: 'manuscriptCategoryId',
                displayField: 'manuscriptCategoryName',
                id : 'manuscriptCategoryName',
                listeners: {
                    "focus": function(){
                        if (storeCategory.getTotalCount() == 0) {
                            Ext.Msg.show({
                                title: '操作提示',
                                msg: '请管理员添加稿件分类!',
                                buttons: Ext.Msg.OK,
                                icon: Ext.Msg.INFO,
                                width: 200
                            });
                        }
                    }
                }
            }, {
                xtype: 'combo',
                store: storeLanguage,
                hiddenName: 'manuscript.language',
                allowBlank: false,
                editable: false,
                fieldLabel: '原稿文种',
                emptyText: '请选择',
                mode: 'local',
                itemCls: 'form_text',
                triggerAction: 'all',
                valueField: 'value',
                displayField: 'text',
                id : 'language'
            }, {
                xtype: 'combo',
                store: storeLanguage,
                hiddenName: 'manuscript.targetLanguage',
                allowBlank: false,
                editable: false,
                fieldLabel: '目标语言',
                emptyText: '请选择',
                mode: 'local',
                itemCls: 'form_text',
                triggerAction: 'all',
                valueField: 'value',
                displayField: 'text',
                 id : 'targetLanguage'
            }, {
                xtype: 'combo',
                store: storeUrgence,
                hiddenName: 'manuscript.urgence',
                allowBlank: false,
                editable: false,
                fieldLabel: '紧急程度',
                emptyText: '请选择',
                mode: 'local',
                triggerAction: 'all',
                itemCls: 'form_text',
                valueField: 'value',
                displayField: 'text'
            },{
                xtype: 'combo',
                store: storeSecurity,
                hiddenName: 'manuscript.securityClassification',
                allowBlank: false,
                editable: false,
                fieldLabel: '密级',
                emptyText: '请选择',
                mode: 'local',
                triggerAction: 'all',
                itemCls: 'form_text',
                valueField: 'value',
                displayField: 'text'
            },{
            	xtype: 'textfield',
		        name: 'manuscript.wordNum',
		        allowBlank: false,
		        fieldLabel: '字数',
		        regex:/^[1-9][0-9]{0,8}$/,
		        regexText:'请输入长度小于等于9且最小值为1的合法正整数',
		        itemCls:'form_text'
            }, {
                xtype: 'datefield',
                name: 'plannedConsummationTime',
                editable: false,
                minValue: new Date().format('Y-m-d'),
                allowBlank: false,
                emptyText: '请选择',
                fieldLabel: '计划完成时间',
                itemCls: 'form_text',
                format: 'Y-m-d'
            }]
        }]
    }, {
        xtype: 'textarea',
        name: 'manuscript.remark',
        allowBlank: true,
        fieldLabel: '备注',
        maxLength: 200,
        maxLengthText: '输入文字过长,请限制在200字内!',
        validator: function(value){
              if (value.indexOf('<') != -1 || value.indexOf('>') != -1) {
                    return false;
               }
        },
        invalidText: '输入不合法:不能带<>等特殊符号',
        itemCls: 'clear form_long',
        width: '420',
        height: '100'
    }],
     	buttons : [{
     		text : '新增',
			type : 'submit',
			handler : function() {
     		if(form_receiver.form.isValid()){
     			Ext.Msg.confirm('新增确认', '你确定要新增稿件?', function(btn) {
     				if (btn == 'yes') {
     					
     					var language = Ext.getCmp('language').getValue();
     					var targetLanguage = Ext.getCmp('targetLanguage').getValue();
     					if(targetLanguage == language)
     					{
     						Ext.Msg.show({
     							title : '错误提示',
     							msg : '目标语言和原稿文种必须不一样！',
     							buttons : Ext.Msg.OK,
     							icon : Ext.Msg.INFO,
     							width : 200
     						});
     						return;
     					} 
     					
     					form_receiver.form.doAction('submit',{
     						url : 'admin_manuscript_add.action',
     						method : 'post',
     						waitTitle:'正在处理' ,
	    					waitMsg: '请稍等......',
     						success : function(form,action) {
     						form_receiver.el.unmask();
     						if (action.result.success) {
    							if(action.result.uploadSuccess==undefined){
    								Ext.Msg.show({
    									title: '操作提示',
    									msg: '文件大于最大允许值50M!',
    									buttons: Ext.Msg.OK,
    									icon: Ext.Msg.ERROR,
    									width: 200
    								});
    							}else if(action.result.uploadSuccess=="true"){
    								Ext.Msg.show({
    									title: '操作提示',
    									msg: '添加成功!',
    									buttons: Ext.Msg.OK,
    									icon: Ext.Msg.INFO,
    									width: 200,
    									fn:function(){
    										window_add_manuscript.remove(Ext.getCmp('mmd'));
     										window_add_manuscript.close();
    									}
    								});
    							}
    					}else {
    						Ext.Msg.show({
    							title: '错误提示',
    							msg: action.result.errorMessage,
    							buttons: Ext.Msg.OK,
    							icon: Ext.Msg.ERROR,
    							width: 200
    						});
    					}
    				
     						
     						ds.load({params:{start:0,limit:20}});
     					},
     					failure : function(form, action) {
     						form_receiver.el.unmask();
     						if(action.result == null){
     							Ext.Msg.show({
     								title : '错误提示',
     								msg : '数据不符合要求！',
     								buttons : Ext.Msg.OK,
     								icon : Ext.Msg.ERROR,
     								width : 200
     							});
     						}else{
     							if(!action.result.success){
     								Ext.Msg.show({
     									title : '错误提示',
     									msg : action.result.errorMessage,
     									buttons : Ext.Msg.OK,
     									icon : Ext.Msg.ERROR,
     									width : 200
     								});
     							}
     						}
     					}
     					});
     				}
     			});
     		}
			}
     	},{
     		text : '重置',
     		handler : function() {
     		form_receiver.form.reset();
			}
     	},{
     		
     		text:'取消',
     		handler:function(){
     			window_add_manuscript.remove(Ext.getCmp('mmd'));
     			window_add_manuscript.close();
     		}
     	}]
     });
		var window_add_manuscript = new Ext.Window({
					title : '新增稿件',
					width : 650,
			        height:700,
					iconCls:'manuscript_add',
					resizable : false,
					autoHeight : true,
					constrain :true,
					modal : true,
					closeAction : 'hide',
					closable : false,
					items : form_receiver
				}).show();

	}
});
var list_allManuscripts = new Ext.Button({

			text : '列出所有稿件',
			width : 100,
			iconCls:'refresh',
			handler : function() {
				ds.baseParams = null;
				ds.load({
							params : {
								start : 0,
								limit : 20,
								requesterSecurityGrade : '5',
								manuscriptStatus : '',
								manuscriptType : '',
								startTime : '',
								endTime : '',
								order : 0
							}
						});
			}

		});

var grid = new Ext.grid.GridPanel({
			title : '当前位置：稿件管理',
			loadMask : {
				msg : '数据加载中...'
			},
			ds : ds,
			store : ds,
			region : 'center',
			autoScroll : true,
			cm : cm_menuscript,
			autoExpandColumn : 1,
			tbar : [select_manuscript, add_manuscript, list_allManuscripts],
			bbar : new Ext.PagingToolbar({
						pageSize : 20,
						store : ds,
						displayInfo : true,
						beforePageText : '第',
						afterPageText : '页-共{0}页',
						displayMsg : '显示{0} - {1} 条  共 {2} 条',
						emptyMsg : "没有记录"
					})
		});
ds.load({
			params : {
				start : 0,
				limit : 20
			}
		});

		
function changeRemark(respText){
    return "<div align=\"center\"><a href='javascript:void(0)'  onclick=javascript:showRemark('" + respText.manuscript.manuscriptId + "')>备注详情</a></div>";
}

window.showRemark = function(v){
    Ext.Ajax.request({
        url: 'manuscript_view.action',
        method: 'post',
        params: {
            manuscriptId: v
        },
        success: function(resp, opts){
            var respText = Ext.util.JSON.decode(resp.responseText);
            if (respText.success) {
                var window_remark = new Ext.Window({
                    title: '备注详情',
                    closable: false,
                    width: 600,
                    resizable: false,
                    height: 400,
                    iconCls: 'manuscript',
                    modal: true,
                    constrain: true,
                    closeAction: 'close',
                    layout: 'fit',
                    items: [{
                        xtype: 'htmleditor',
                        enableAlignments: false,
                        enableColors: false,
                        enableFont: false,
                        enableFontSize: false,
                        enableFormat: false,
                        enableLinks: false,
                        enableLists: false,
                        enableSourceEdit: false,
                        readOnly: true,
                        value: respText.manuscript.remark
                    }],
                    buttons: [{
                        text: '关闭',
                        handler: function(){
                            window_remark.close();
                        }
                    }]
                
                
                }).show();
            }
        },
        failure: function(){
            Ext.Msg.show({
                title: '错误提示',
                msg: '查看失败!',
                buttons: Ext.Msg.OK,
                icon: Ext.Msg.ERROR,
                width: 200
            });
        }
    })
}
	
		
window.showManuscript = function(needParam) {
	Ext.Ajax.request({
		url : 'manuscript_view.action',
		method : 'post',
		params : {
			manuscriptId : needParam
		},
		success : function(resp, opts) {
			var respText = Ext.util.JSON.decode(resp.responseText);
			var manuscript = respText.manuscript;
			var type = '';
			var language = '';
			var targetLanguage = '';
			var status = '';
			var urgence = '';
			var securityClassification = '';
			if (manuscript.type == 0) {
				type = '纸质稿件';
			} else {
				type = '电子稿件';
			}
			if (manuscript.language == 1) {
				language = '汉语';
			} else {
				language = '藏语';
			}
			if (manuscript.targetLanguage == 1) {
				targetLanguage = '汉语';
			} else {
				targetLanguage = '藏语';
			}
			if (manuscript.status == 0) {
				status = '草稿';
			} else if (manuscript.status == 1) {
				status = '原稿';
			} else if (manuscript.status == 2) {
				status = '翻译中';
			} else if (manuscript.status == 3) {
				status = '翻译完成';
			} else if (manuscript.status == 4) {
				status = '校审中';
			} else if (manuscript.status == 5) {
				status = '校审完成';
			} else if (manuscript.status == 6) {
				status = '校对中';
			} else if (manuscript.status == 7) {
				status = '校对完成';
			} else if (manuscript.status == 8) {
				status = '审核中';
			} else if (manuscript.status == 9) {
				status = '审核完成';
			} else {
				status = '已发排';
			};
			if (manuscript.urgence == 0) {
				urgence = '普通';
			} else if (manuscript.urgence == 5) {
				urgence = '紧急';
			} else if (manuscript.urgence == 10) {
				urgence = '特急';
			}

			if (manuscript.securityClassification == 1) {
				securityClassification = '普通';
			} else if (manuscript.securityClassification == 2) {
				securityClassification = '秘密';
			} else if (manuscript.securityClassification == 3) {
				securityClassification = '机密';
			} else if (manuscript.securityClassification == 5) {
				securityClassification = '绝密';
			}

			if (respText.success) {
				var manuscript_show=new Ext.Window({
					title : '稿件详情',
					width : 600,
					iconCls:'manuscript_manager',
					resizable : false,
					autoHeight : true,
					constrain :true,
					modal : true,
					closeAction : 'hide',
					closable : false,
					items : [new Ext.FormPanel({
								border : false,
								frame : true,
								labelAlign : 'right',
								labelWidth : 100,
								defaults : {
									itemCls : 'form_text unedit',
									msgTarget : 'side'
								},
								defaultType : 'textfield',
								items : [{
											fieldLabel : '稿件标题',
											value : manuscript.title,
											readOnly : true,
											itemCls : 'form_long clear unedit',
											width : 426
										},{
											autoHeight : true,
											xtype : 'textfield',
											fieldLabel : '稿件编号',
											readOnly : true,
											value : respText.manuscript.manuscriptCode,
											itemCls:'form_text unedit'
										}, {
											fieldLabel : '文档类型',
											value : type,
											readOnly : true
										}, {
											fieldLabel : '稿件分类',
											value : manuscript.manuscriptCategory.manuscriptCategoryName,
											readOnly : true
										}, {
											fieldLabel : '来稿单位',
											value : manuscript.contributeCompany.contributeCompanyName,
											readOnly : true
										}, {
											xtype : 'textfield',
											fieldLabel : '来稿单位类型',
											readOnly : true,
											value : respText.manuscript.contributeCompany.type,
											itemCls:'form_text unedit'
										}, {
											fieldLabel : '联系人',
											value : manuscript.contributeCompanyPerson.name,
											readOnly : true
										},{
											fieldLabel : '联系人手机',
											value : manuscript.contributeCompanyPerson.mobilePhone,
											readOnly : true
										},{
											fieldLabel : '联系人电话',
											value : manuscript.contributeCompanyPerson.telephone,
											readOnly : true
										},{
											fieldLabel : '联系人邮箱',
											value : manuscript.contributeCompanyPerson.email,
											readOnly : true
										},{
											fieldLabel : '原稿文种',
											value : language,
											readOnly : true
										}, {
											fieldLabel : '目标语言',
											value : targetLanguage,
											readOnly : true
										}, {
											fieldLabel : '稿件状态',
											value : status,
											readOnly : true
										},{
											fieldLabel : '紧急程度',
											value : urgence,
											readOnly : true
										}, {
											fieldLabel : '稿件密级',
											value : securityClassification,
											readOnly : true
										}, {
											fieldLabel : '字数',
											value : manuscript.wordNum,
											readOnly : true
										}, {
											fieldLabel : '稿件创建人',
											value : manuscript.creatorName,
											readOnly : true
										}, {
											fieldLabel : '来稿时间',
											value : formatTime(manuscript.contributeTime,"",""),
											readOnly : true
										}, {
											fieldLabel : '计划完成时间',
											value : formatTime(manuscript.plannedConsummationTime,"",""),
											readOnly : true
										},{
											fieldLabel : '实际完成时间',
											value : formatTime(manuscript.actualConsummationTime,"",""),
											readOnly : true
										}, {
											fieldLabel : '最后修改人',
											value : manuscript.lastModifierName,
											readOnly : true
										}, {
											fieldLabel : '最后修改时间',
											value : formatTime(manuscript.lastModifiedTimestamp,"",""),
											readOnly : true
										}, {
											fieldLabel : '发排人',
											value : manuscript.releaserName,
											readOnly : true
										}, {
											fieldLabel : '发排时间',
											value : formatTime(manuscript.releaseTimeStamp,"",""),
											readOnly : true
										}, {
											 fieldLabel: '备注',
					                         xtype: 'panel',
					                         width: 425,
					                         itemCls: 'clear',
					                         html: changeRemark(respText)
										}],	
								buttons:[{
								text:'关闭',
								handler:function(){
								manuscript_show.close();
							}
							}]	
							
							})]

				}).show();
			} else {
				Ext.Msg.show({
					title : '错误提示',
					msg : '查看稿件详情失败！',
					buttons : Ext.Msg.OK,
					icon : Ext.Msg.INFO,
					width : 200
				});
			}
		},
		failure : function() {
			Ext.Msg.show({
						title : '错误提示',
						msg : '查看稿件详情失败！',
						buttons : Ext.Msg.OK,
						icon : Ext.Msg.ERROR,
						width : 200
					});
		}
	});
};

window.modifyScript = function(needParam) {
	Ext.Ajax.request({
		url : 'manuscript_view.action',
		method : 'post',
		params : {
			manuscriptId : needParam
		},
		success : function(resp, opts) {
			var respText = Ext.util.JSON.decode(resp.responseText);
			var manuscript = respText.manuscript;
			var contributeCompany = respText.contributeCompany;
			var contributeCompanyPerson = respText.contributeCompanyPerson;
			var manuscriptCategory = respText.manuscriptCategory;

			if (respText.success) {
				
					modifyManuscriptForm = new Ext.FormPanel({
						frame : true,
						labelAlign : 'right',
						labelWidth : 95,
						defaultType : 'textfield',
						id : 'mmf',
						items : [{
									fieldLabel : '稿件标题',
									name : 'title',
									value : manuscript.title,
									validator: function(value){
								    	var regex=/[\S]/;
								    	return regex.test(value);
									 },
									 invalidText: '稿件标题不合法:不能为空',
									itemCls : 'form_long clear',
									width : 426
								}, {
									xtype : 'combo',
									id:'contributeCompanyName',
									store : storeContributeCompany,
									fieldLabel : '来稿单位',
									value:contributeCompany.contributeCompanyName,
									editable : false,
									forceSelection : true,
									typeAhead : true,
									maxHeight:150,
									mode : 'local',
									triggerAction : 'all',
									hiddenName : 'contributeCompanyId',
									valueField : 'contributeCompanyId',
									displayField : 'contributeCompanyName',
									validator:function(){
										return true;
									} ,
									itemCls : 'form_text',
									listeners : {
										'valid':function(){
											if(contributeCompany.contributeCompanyName==Ext.getCmp('contributeCompanyName').getValue()){
												Ext.getCmp('contributeCompanyName').hiddenField.value = contributeCompany.contributeCompanyId;
											}
										},
										'select' : function() {
											storeContributeCompanyPerson.baseParams.contributeCompanyId=Ext.getCmp('contributeCompanyName').getValue();
											storeContributeCompanyPerson.load();
											Ext.getCmp('contributeCompanyPerson_manuscript_two').setValue('');
											Ext.getCmp('contributeCompanyPerson_manuscript_two').allowBlank = false;
										}
									}
								}, {
									xtype : 'combo',
									store : storeContributeCompanyPerson,
									fieldLabel : '联系人',
									value:contributeCompanyPerson.name,
									editable : false,
									forceSelection : true,
									typeAhead : true,
									mode : 'local',
									triggerAction : 'all',
									id : 'contributeCompanyPerson_manuscript_two',
									hiddenName : 'contributeCompanyPersonId',
									valueField : 'contributeCompanyPersonId',
									displayField : 'name',
									validator:function(){
										return true;
									} ,
									itemCls : 'form_text',
									listeners:{
										'valid':function(){
											var length=storeContributeCompanyPerson.getTotalCount();
											if(Ext.getCmp('contributeCompanyName').getValue()==contributeCompany.contributeCompanyName){
												if(Ext.getCmp('contributeCompanyPerson_manuscript_two').getValue()==contributeCompanyPerson.name){
														Ext.getCmp('contributeCompanyPerson_manuscript_two').hiddenField.value = contributeCompanyPerson.contributeCompanyPersonId;
														
												}else{
													return;
												}
											}
										},
							    		 "focus":function(){
												if(Ext.getCmp('contributeCompanyName').getValue()==contributeCompany.contributeCompanyName){
													storeContributeCompanyPerson.baseParams.contributeCompanyId=contributeCompany.contributeCompanyId;
													storeContributeCompanyPerson.load();
												}/*else if(storeContributeCompanyPerson.getTotalCount() == 0){
								    		 		Ext.Msg.show({
																title : '操作提示',
																msg : '该来稿单位无联系人！',
																buttons : Ext.Msg.OK,
																icon : Ext.Msg.INFO,
																width : 200
															});
								    		 	}*/
								    		 }
							    		 }
								}, {
									xtype : 'combo',
									id:'manuscriptCategory',
									store : storeCategory,
									fieldLabel : '稿件类型',
//									emptyText : manuscriptCategory.manuscriptCategoryName,
									value:manuscriptCategory.manuscriptCategoryName,
									editable : false,
									forceSelection : true,
									typeAhead : true,
									mode : 'local',
									triggerAction : 'all',
									hiddenName : 'manuscriptCategoryId',
									valueField : 'manuscriptCategoryId',
									displayField : 'manuscriptCategoryName',
									validator:function(){
										return true;
									} ,
									itemCls : 'form_text',
									listeners:{
										'valid':function(){
											var length=storeCategory.getTotalCount();
											if(Ext.getCmp('manuscriptCategory').getValue()==manuscriptCategory.manuscriptCategoryName){
													Ext.getCmp('manuscriptCategory').hiddenField.value = manuscriptCategory.manuscriptCategoryId;
												
											}
										},
							    		 "focus":function(){
								    		 	if(storeCategory.getTotalCount() == 0){
								    		 		Ext.Msg.show({
																title : '操作提示',
																msg : '请管理员添加稿件分类！',
																buttons : Ext.Msg.OK,
																icon : Ext.Msg.INFO,
																width : 200
															});
								    		 	}
								    		 }
							    		 }
								},{
									xtype : 'combo',
									store : new Ext.data.SimpleStore({
												data : [['0', '普通'],
														['5', '紧急'],
														['10','特急']],
												fields : ['value', 'text']
											}),

									hiddenName : 'manuscript.urgence',
									allowBlank : false,
									editable : false,
									fieldLabel : '紧急程度',
									emptyText : '请选择',
									mode : 'local',
									triggerAction : 'all',
									valueField : 'value',
									displayField : 'text',
									value : manuscript.urgence,
									itemCls : 'form_text'
								}, {
									xtype : 'datefield',
									name : 'plannedConsummationTime',
									editable : false,
									allowBlank : false,
									fieldLabel : '计划完成时间',
									format : 'Y-m-d',
									value :  new Date(manuscript.plannedConsummationTime).format('Y-m-d'),//formatTime(manuscript.plannedConsummationTime,"",""),
									itemCls : 'form_text',
									minValue : new Date().format('Y-m-d')
								}, {
									xtype : 'textarea',
									fieldLabel : '稿件备注',
									name : 'remark',
									itemCls : 'clear',
									width : 426
								}, {
									xtype : 'hidden',
									name : 'manuscript.manuscriptId',
									value : manuscript.manuscriptId
								}],
								buttons : [{
									text : '确定',
									type : 'submit',
									handler : function() {
										if (modifyManuscriptForm.form.isValid()) {
											modifyManuscriptForm.form.doAction('submit', {
												url : 'manuscript_edit.action',// 文件路径
												method : 'post',// 提交方法post或get
												waitTitle:'正在处理' ,
						    					waitMsg: '请稍等......',
												params : '',
												success : function(form, action) {
													if (action.result.msg == 'wrong') {
														Ext.Msg.show({
																	title : '错误提示',
																	msg : '稿件已发排，不能修改',
																	buttons : Ext.Msg.OK,
																	icon : Ext.Msg.ERROR,
																	width : 200
																});
													} else if (action.result.msg == 'ok') {
														Ext.Msg.show({
																	title : '消息',
																	msg : '修改稿件成功!',
																	buttons : Ext.Msg.OK,
																	icon : Ext.Msg.INFO,
																	width : 200
																});
														manuscript_window.close();
														ds.load({
																	params : {
																		start : 0,
																		limit : 20
																	}
																});
														manuscript_window.remove(Ext.getCmp('mmf'));
													}
												},
												failure : function(form, action) {
													if (action.failureType == 'server') {
														Ext.Msg.show({
															title : '错误',
															msg : '修改稿件失败',
															buttons : Ext.Msg.OK,
															icon : Ext.Msg.INFO,
															width : 200
														});
													} else 
						                                    if (action.failureType == 'connect') {
						                                        Ext.Msg.show({
																	title : '连接错误',
																	msg : '指定路径连接错误!',
																	buttons : Ext.Msg.OK,
																	icon : Ext.Msg.ERROR,
																	width : 200
																});
						                                    }
						                                    else 
						                                        if (action.failureType == 'client') {
						                                            Ext.Msg.show({
																		title : '提示',
																		msg : '数据错误，非法提交',
																		buttons : Ext.Msg.OK,
																		icon : Ext.Msg.ERROR,
																		width : 200
																	});
						                                        }
						                                        else {
						                                            Ext.Msg.show({
																		title : '警告',
																		msg : '服务器数据传输错误',
																		buttons : Ext.Msg.OK,
																		icon : Ext.Msg.ERROR,
																		width : 200
																	});
						                                        }
													manuscript_window.remove(Ext.getCmp('mmf'));
												}
											});
										}
									}
								},{
									text:'取消',
									handler : function() {
										manuscript_window.close();
										manuscript_window.remove(Ext.getCmp('mmf'));
									}
								}]
							
					}),
				manuscript_window = new Ext.Window({
					title : '编辑稿件信息',
					width : 600,
					iconCls:'manuscript_edit',
					resizable : false,
					autoHeight : true,
					constrain :true,
					modal : true,
					closeAction : 'hide',
					closable : false,
					items : modifyManuscriptForm
				}).show();
		
			} else {
				Ext.Msg.show({
					title : '错误提示',
					msg : '查看稿件详情失败！',
					buttons : Ext.Msg.OK,
					icon : Ext.Msg.ERROR,
					width : 200
				});
			}
		},
		failure : function() {
			Ext.Msg.show({
						title : '错误提示',
						msg : '修改稿件信息失败！',
						buttons : Ext.Msg.OK,
						icon : Ext.Msg.ERROR,
						width : 200
					});
		}
	});
};

window.deleteScript = function(needParam) {
	Ext.Msg.confirm('删除确认', '你确定删除?', function(btn) {
				if (btn == 'yes') {
					Ext.Ajax.request({
								url : "manuscript_delete.action",
								method : 'post',
								params : {
									manuscriptId : needParam
								},
								success : function(resp, opts) {
									var respText = Ext.util.JSON
											.decode(resp.responseText);
									if (respText.success) {
										if (respText.msg == 'wrong') {
											Ext.Msg.show({
														title : '错误',
														msg : '稿件未完成，不能删除！',
														buttons : Ext.Msg.OK,
														icon : Ext.Msg.ERROR,
														width : 200
													});
										} else if (respText.msg == 'ok') {
											Ext.Msg.show({
														title : '消息',
														msg : '删除成功！',
														buttons : Ext.Msg.OK,
														icon : Ext.Msg.INFO,
														width : 200
													});
											ds.load({
														params : {
															start : 0,
															limit : 20
														}
													});
										}
									} else {
										Ext.Msg.show({
													title : '错误提示',
													msg : '删除失败！',
													buttons : Ext.Msg.OK,
													icon : Ext.Msg.ERROR,
													width : 200
												});
									}
								},
								failure : function() {
									Ext.Msg.show({
												title : '错误提示',
												msg : '删除失败！',
												buttons : Ext.Msg.OK,
												icon : Ext.Msg.ERROR,
												width : 200
											});
								}
							});
				}
			});
}

//时间格式转换
function formatTime(value, metadata, record){
	if(null==value){
		return null;
	}else{
		return new Date(value).format('Y-m-d H:i');
	}
}

var p_menuScript = {
	id : 'manuscript-search',
	border : false,
	layout : 'border',
	items : [grid]
};
Ext.getCmp('content-panel').add(p_menuScript);
Ext.getCmp('content-panel').layout.setActiveItem('manuscript-search');
Ext.getCmp('content-panel').uxmodules="undefined";
